import Vue from 'vue'
import text from './text/text.vue'
import radio from './radio/radio.vue'
import radioSelct from './radio/radioSelect.vue'
import checkboxSelect from './checkbox/checkboxSelect.vue'
import checkbox from './checkbox/checkbox.vue'
import number from './number/number.vue'
import cascadeSelect from './cascadeSelect/cascadeSelect.vue'
import region from './region/region.vue'
import accessory from './accessory/accessory.vue'
import dateTime from './datetime/datetime.vue'
import group from './group/group.vue'
import member from './member/member.vue'
import department from './department/department.vue'
import associateSpare from './associateSpare/associateSpare.vue'
import associateService from './associateService/associateService.vue'
import associateUser from './associateUser/associateUser.vue'
import sign from './sign/sign.vue'
const widgetsConfig = {
  sign,
  associateUser,
  associateService,
  text,
  multiText: text,
  radio,
  radioSelct,
  checkbox,
  checkboxSelect,
  number,
  cascadeSelect,
  region,
  accessory,
  dateTime,
  group,
  member,
  department,
  associateSpare
}

// 工单表单记录
export const widgetInRecord = {
  name: 'widget',
  functional: true,
  props: {
    item: {
      type: Object,
      required: true
    },
    form: Object
  },
  render (createElement, context) {
    const type = context.props.item.fieldType
    let widget = widgetsConfig[type]
    if (type === 'radio') {
      widget = context.props.item.radioType === 1 ? radioSelct : radio
    } else if (type === 'checkbox') {
      widget = context.props.item.checkboxType === 1 ? checkboxSelect : checkbox
    }
    return createElement(
      widget,
      { props: context.props, ...context.data }
    )
  }
}

// 表单配置导出
export const widgetConfig = Vue.component('widgetWrap', {
  functional: true,
  props: {
    isConfig: Boolean,
    item: {
      type: Object,
      required: true
    },
    form: Object
  },
  render (createElement, context) {
    const type = context.props.item.fieldType
    let widget = widgetsConfig[type]
    if (type === 'radio') {
      widget = context.props.item.radioType === 1 ? radioSelct : radio
    } else if (type === 'checkbox') {
      widget = context.props.item.checkboxType === 1 ? checkboxSelect : checkbox
    }
    return createElement(
      widget,
      { ...context.data, props: context.props }
    )
  }
})
